<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>从字符串中的图像流新建一图像</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.imagecreatefrompng.html">imagecreatefrompng</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.imagecreatefromwbmp.html">imagecreatefromwbmp</a></div>
 <div class="up"><a href="ref.image.html">GD and Image 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.imagecreatefromstring" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">imagecreatefromstring</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.0.4, PHP 5)</p><p class="refpurpose"><span class="refname">imagecreatefromstring</span> &mdash; <span class="dc-title">从字符串中的图像流新建一图像</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.imagecreatefromstring-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">resource</span> <span class="methodname"><strong>imagecreatefromstring</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$image</code></span>
   )</div>

  <p class="para rdfs-comment">
   <span class="function"><strong>imagecreatefromstring()</strong></span>
   返回一个图像标识符，其表达了从给定字符串得来的图像。图像格式将自动检测，只要
   PHP 支持：JPEG，PNG，GIF，WBMP 和 GD2。
  </p>
 </div>

 <div class="refsect1 parameters" id="refsect1-function.imagecreatefromstring-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<em><code class="parameter">image</code></em></dt>

     <dd>

      <p class="para">
       A string containing the image data.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-function.imagecreatefromstring-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   An image resource will be returned on success. <strong><code>FALSE</code></strong> is returned if
   the image type is unsupported, the data is not in a recognised format,
   or the image is corrupt and cannot be loaded.
  </p>
 </div>

 <div class="refsect1 examples" id="refsect1-function.imagecreatefromstring-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-3144">
    <p><strong>Example #1 <span class="function"><strong>imagecreatefromstring()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$data&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'iVBORw0KGgoAAAANSUhEUgAAABwAAAASCAMAAAB/2U7WAAAABl'<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">'BMVEUAAAD///+l2Z/dAAAASUlEQVR4XqWQUQoAIAxC2/0vXZDr'<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">'EX4IJTRkb7lobNUStXsB0jIXIAMSsQnWlsV+wULF4Avk9fLq2r'<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">'8a5HSE35Q3eO2XP1A1wQkZSgETvDtKdQAAAABJRU5ErkJggg=='</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$data&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">base64_decode</span><span style="color: #007700">(</span><span style="color: #0000BB">$data</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$im&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">imagecreatefromstring</span><span style="color: #007700">(</span><span style="color: #0000BB">$data</span><span style="color: #007700">);<br />if&nbsp;(</span><span style="color: #0000BB">$im&nbsp;</span><span style="color: #007700">!==&nbsp;</span><span style="color: #0000BB">false</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">header</span><span style="color: #007700">(</span><span style="color: #DD0000">'Content-Type:&nbsp;image/png'</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">imagepng</span><span style="color: #007700">(</span><span style="color: #0000BB">$im</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">imagedestroy</span><span style="color: #007700">(</span><span style="color: #0000BB">$im</span><span style="color: #007700">);<br />}<br />else&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'An&nbsp;error&nbsp;occurred.'</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程的输出类似于：</p></div>
    <div class="mediaobject">
     
     <div class="imageobject">
      <img src="images/21009b70229598c6a80eef8b45bf282b-imagecreatefromstring.png" alt="Output of example : imagecreatefromstring()" width="28" height="18" />
     </div>
    </div>
   </div>
  </p>
 </div>

 <div class="refsect1 seealso" id="refsect1-function.imagecreatefromstring-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.imagecreatefromjpeg.html" class="function" rel="rdfs-seeAlso">imagecreatefromjpeg()</a> - 由文件或 URL 创建一个新图象。</span></li>
    <li class="member"><span class="function"><a href="function.imagecreatefrompng.html" class="function" rel="rdfs-seeAlso">imagecreatefrompng()</a> - 由文件或 URL 创建一个新图象。</span></li>
    <li class="member"><span class="function"><a href="function.imagecreatefromgif.html" class="function" rel="rdfs-seeAlso">imagecreatefromgif()</a> - 由文件或 URL 创建一个新图象。</span></li>
    <li class="member"><span class="function"><a href="function.imagecreatetruecolor.html" class="function" rel="rdfs-seeAlso">imagecreatetruecolor()</a> - 新建一个真彩色图像</span></li>
   </ul>
  </p>
 </div>

</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.imagecreatefrompng.html">imagecreatefrompng</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.imagecreatefromwbmp.html">imagecreatefromwbmp</a></div>
 <div class="up"><a href="ref.image.html">GD and Image 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
